package com.example.spzx.controller;

import com.example.spzx.Mapper.ProductSpecMapper;
import com.example.spzx.Service.ProductSpecService;
import com.example.spzx.model.entity.product.ProductSpec;
import com.example.spzx.model.vo.common.Result;
import com.example.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/admin/product/productSpec")
@RestController
public class ProductSpecController {
    @Resource
    private ProductSpecMapper productSpecMapper;
    @Resource
    private ProductSpecService productSpecService;
    @GetMapping("/{page}/{limit}")
    public Result<ProductSpec> list(@PathVariable("page") Integer page,@PathVariable("limit") Integer limit){
        PageInfo<ProductSpec> pageInfo=productSpecService.getpage(page,limit);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }
    @PostMapping("/save")
    public Result<ProductSpec> save(@RequestBody ProductSpec productSpec){
        productSpecService.add(productSpec);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    @PutMapping("/updateById")
    public Result<ProductSpec> updateById(@RequestBody ProductSpec productSpec){
        productSpecService.updateById(productSpec);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    @DeleteMapping("/deleteById/{id}")
    public Result<ProductSpec> deleteById(@PathVariable("id") Integer id){
        productSpecService.delete(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    @GetMapping("/all")
    public Result<ProductSpec> all(){
        List<ProductSpec> list=productSpecMapper.getall();
        return Result.build(list,ResultCodeEnum.SUCCESS);
    }
}
